#include "kswidgetback.h"

#define WBLEFT 180
#define WBMID 360

KSWidgetBack::KSWidgetBack(QWidget* parent /*= 0*/) : QWidget(parent)
{
	//		setBackgroundRole(true);
	m_backimgfull = QPixmap(":/main_down_back");

	int w = m_backimgfull.width();
	int h = m_backimgfull.height();

	
	m_backimg1 = m_backimgfull.copy(QRect(0, 0, WBLEFT, h));
	int x2 = WBLEFT;
	int y2 = 0;
	int w2 = w / 2 - WBMID;

	m_backimg2 = m_backimgfull.copy(QRect(x2, y2, w2, h));

	int x3 = w / 2 - WBLEFT;
	int y3 = 0;
	int w3 = WBMID;
	
	m_backimg3 = m_backimgfull.copy(QRect(x3, y3, w3, h));

	int x4 = w / 2 + WBLEFT;
	int y4 = 0;
	int w4 = w2;

	m_backimg4 = m_backimgfull.copy(QRect(x4, y4, w4, h));

	int x5 = w - WBLEFT;
	int y5 = 0;
	int w5 = WBLEFT;
	
	m_backimg5 = m_backimgfull.copy(QRect(x5, y5, w5, h));
	//repaint();
}



void KSWidgetBack::paintEvent(QPaintEvent *e)
{
	ResetData();
	QPainter painter;
	painter.begin(this);

	

	painter.drawPixmap(rectarrvy[0], m_backimg1);
	painter.drawPixmap(rectarrvy[1], m_backimg2.scaled(rectarrvy[1].width(), rectarrvy[1].height()));
	painter.drawPixmap(rectarrvy[2], m_backimg3);
	painter.drawPixmap(rectarrvy[3], m_backimg4.scaled(rectarrvy[3].width(), rectarrvy[3].height()));
	painter.drawPixmap(rectarrvy[4], m_backimg5);
	
	painter.end();
	QWidget::paintEvent(e);
}

void KSWidgetBack::ResetData()
{
	rectarrvy.clear();
	int w = rect().width();
	int h = m_backimgfull.height();

	rectarrvy.push_back(QRect(0, 0, WBLEFT, h));
	
	int x2 = WBLEFT;
	int y2 = 0;
	int w2 = w / 2 - WBMID;
	rectarrvy.push_back(QRect(x2, y2, w2+1, h));	

	int x3 = w / 2 - WBLEFT;
	int y3 = 0;
	int w3 = WBMID;
	rectarrvy.push_back(QRect(x3, y3, w3, h));	

	int x4 = w / 2 + WBLEFT;
	int y4 = 0;
	int w4 = w2;
	rectarrvy.push_back(QRect(x4, y4, w4+1, h));	

	int x5 = w - WBLEFT;
	int y5 = 0;
	int w5 = WBLEFT;
	rectarrvy.push_back(QRect(x5, y5, w5, h));	
}
